package com.text
{
	
	/**
	* CharacterSet provides data sets representing word characters.
	* You can change these values at run-time to support different lanugages.
	* This is primarily intended for use by TextHighlighter and SpellingDictionary.
	**/
   internal class CharacterSet {
		/**
		* A string containing the default roman word characters.
		**/
		public static const DEFAULT_WORD_CHARS:String = "abcdefghijklmnopqrstuvwxyzÃ Ã¡Ã¢Ã£Ã¤Ã¥Ã¦Ã§Ã¨Ã©ÃªÃ«Ã¬Ã­Ã®Ã¯Ã°Ã±Ã²Ã³Ã´ÃµÃ¶Ã¸Ã¹ÃºÃ»Ã¼Ã½Ã¾Ã¿ÃŸ";
		
		/**
		* A string containing the default roman inner word characters.
		**/
		private static const DEFAULT_INNER_WORD_CHARS:String = "'â€™";
		
		/**
		* A string containing the default roman invalid word characters.
		**/
		private static const DEFAULT_INVALID_WORD_CHARS:String = "0123456789";
		
	// private properties
		private static var _wordCharSet:Array;
		private static var _innerWordCharSet:Array;
		private static var _invalidWordCharSet:Array;
		private static var _wordChars:String = DEFAULT_WORD_CHARS;
		private static var _innerWordChars:String = DEFAULT_INNER_WORD_CHARS;
		private static var _invalidWordChars:String = DEFAULT_INVALID_WORD_CHARS;
		
		/**
		* @private
		**/
		public function CharacterSet() {
			throw(new Error("CharacterSet cannot be instantiated"));
		}
		
	// public getter / setters
		/**
		* An array having true at each index corresponding to a word character code (lower and upper case).
		**/
		public static function get wordCharSet():Array {
			if (_wordCharSet == null) {
				_wordCharSet = prepCharCodeArray(_wordChars);
			}
			return _wordCharSet;
		}
		
		/**
		* An array having true at each index corresponding to an inner word character code (lower and upper case).
		**/
		public static function get innerWordCharSet():Array {
			if (_innerWordCharSet == null) {
				_innerWordCharSet = prepCharCodeArray(_innerWordChars);
			}
			return _innerWordCharSet;
		}
		
		/**
		* An array having true at each index corresponding to an invalid word character code (lower and upper case).
		**/
		public static function get invalidWordCharSet():Array {
			if (_invalidWordCharSet == null) {
				_invalidWordCharSet = prepCharCodeArray(_invalidWordChars);
			}
			return _invalidWordCharSet;
		}
		
		/**
		* A string containing all of the lower case characters that are considered to be part of a word.
		**/
		public static function get wordChars():String {
			return _wordChars;
		}
		public static function set wordChars(value:String):void {
			_wordCharSet = null;
			_wordChars = value;
		}
		
		/**
		* A string containing all of the lower case characters that are considered to be part of a word,
		* but must be contained within characters from the word chars set. For example:
		* in "don't" the inner character "'" is considered part of the word, but in "'monkey'" it is not.
		**/
		public static function get innerWordChars():String {
			return _innerWordChars;
		}
		public static function set innerWordChars(value:String):void {
			_innerWordCharSet = null;
			_innerWordChars = value;
		}
		
		/**
		* A string containing all of the lower case characters that invalidate a word if it comprises them.
		**/
		public static function get invalidWordChars():String {
			return _invalidWordChars;
		}
		public static function set invalidWordChars(value:String):void {
			_invalidWordCharSet = null;
			_invalidWordChars = value;
		}
		
	// private methods
		private static function prepCharCodeArray(str:String):Array {
			var l:uint = str.length;
			var a:Array = [];
			for (var i:uint=0; i<l; i++) {
				a[str.charCodeAt(i)] = true;
				a[str.charAt(i).toUpperCase().charCodeAt(0)] = true;
			}
			return a;
		}
		
		
	}
	
}
